//  routesFromDB
//  routesForNav  tree
//  routesForRouter  appContextRouteConfig_children
import Convert from "@/utils/TreeFlatConvert";
export function geneRoutesForNav(routesFromDB) {
  let localFlatRoutes = JSON.parse(JSON.stringify(routesFromDB));
  localFlatRoutes.forEach((x) => {
    x.children = [];
  });
  let c = new Convert({
    flatNodes: localFlatRoutes,
  });
  return c.toTreeDirect("routeId", "parentId");
}
export function geneRoutesForRouter(routesFromDB) {
  let localFlatRoutes = JSON.parse(JSON.stringify(routesFromDB));
  let routesForRouter = localFlatRoutes
    .filter((x) => x.viewLevel === 2)
    .filter((x) => x.type === 1)
    .map((x) => {
      return {
        name: x.name,
        path: x.path,
        component: () => import("@/views/" + x.component),
      };
    });
  return routesForRouter;
}
